package com.sky.controller.admin;

import com.sky.constant.BusinessStatusConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "营业状态相关接口")
@RequestMapping("/admin/shop")
public class AdminShopController {
    @Autowired
    private StringRedisTemplate redisTemplate;

    @PutMapping("/{status}")
    @ApiOperation("设置营业状态")
    public Result setShopStatus(@PathVariable Integer status){
        redisTemplate.opsForValue().set(BusinessStatusConstant.BUSINESS_STATUS_KEY,status.toString());
        return Result.success();
    }

    @GetMapping("/status")
    @ApiOperation("查询营业状态")
    public Result queryShopStatus(){
        String status = redisTemplate.opsForValue().get(BusinessStatusConstant.BUSINESS_STATUS_KEY);
        return Result.success(Integer.parseInt(status));
    }
}
